home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Miscellaneous / gdbm / systems.h < prev    next >
Text File  |  1992-12-16  |  4KB  |  158 lines

  1. /* systems.h - Most of the system dependant code and defines are here. */
  2.  
  3. /*  This file is part of GDBM, the GNU data base manager, by Philip A. Nelson.
  4.     Copyright (C) 1990, 1991  Free Software Foundation, Inc.
  5.  
  6.     GDBM is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; either version 1, or (at your option)
  9.     any later version.
  10.  
  11.     GDBM is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU General Public License
  17.     along with GDBM; see the file COPYING.  If not, write to
  18.     the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20.     You may contact the author by:
  21.        e-mail:  phil@wwu.edu
  22.       us-mail:  Philip A. Nelson
  23.                 Computer Science Department
  24.                 Western Washington University
  25.                 Bellingham, WA 98226
  26.         phone:  (206) 676-3035
  27.        
  28. *************************************************************************/
  29.  
  30. #ifdef macintosh
  31. #define OPEN(a,b,c) open(a,b)
  32. #define L_SET SEEK_SET
  33. #include <memory.h>
  34. #define bcmp(d1, d2, n)    memcmp(d1, d2, n)
  35. #define bcopy(d1, d2, n) memcpy(d2, d1, n)
  36. #define fsync(f) 0
  37. #define flock(a,b) 0
  38. #endif
  39.  
  40. /*         System V changes and defines.          */
  41. /**************************************************/
  42.  
  43. #ifdef SYSV
  44.  
  45. /* File seeking needs L_SET defined .*/
  46. #include <unistd.h>
  47. #define L_SET SEEK_SET
  48.  
  49. /* Some files need fcntl.h for locking. */
  50. #include <fcntl.h>
  51. #define UNLOCK_FILE(dbf) \
  52.     {                    \
  53.       struct flock flock;            \
  54.       flock.l_type = F_UNLCK;        \
  55.       flock.l_whence = 0;            \
  56.       flock.l_start = flock.l_len = 0L;    \
  57.       fcntl (dbf->desc, F_SETLK, &flock);    \
  58.     }
  59. #define READLOCK_FILE(dbf) \
  60.     {                    \
  61.       struct flock flock;            \
  62.       flock.l_type = F_RDLCK;        \
  63.       flock.l_whence = 0;            \
  64.       flock.l_start = flock.l_len = 0L;    \
  65.       lock_val = fcntl (dbf->desc, F_SETLK, &flock);    \
  66.     }
  67. #define WRITELOCK_FILE(dbf) \
  68.     {                    \
  69.       struct flock flock;            \
  70.       flock.l_type = F_WRLCK;        \
  71.       flock.l_whence = 0;            \
  72.       flock.l_start = flock.l_len = 0L;    \
  73.       lock_val = fcntl (dbf->desc, F_SETLK, &flock);    \
  74.     }
  75.  
  76. /* Send bcmp to the right place. */
  77. #include <memory.h>
  78. #define bcmp(d1, d2, n)    memcmp(d1, d2, n)
  79. #define bcopy(d1, d2, n) memcpy(d2, d1, n)
  80.  
  81. /* Sys V does not have fsync. */
  82. #define fsync(f) sync(); sync()
  83.  
  84. /* Stat does not have a st_blksize field. */
  85. #define STATBLKSIZE 512
  86.  
  87. /* Does not have rename(). */
  88. #define NEED_RENAME
  89.  
  90. /* Get string definitions. */
  91. #include <string.h>
  92. #define _HAVE_STRING
  93. #endif
  94.  
  95. /* Sys V does not have a truncate call, how primitive. */
  96. #define TRUNCATE(dbf) close( OPEN (dbf->name, O_RDWR|O_TRUNC, mode))
  97.  
  98.  
  99. /*      End of System V changes and defines.      */
  100. /**************************************************/
  101.  
  102.  
  103.  
  104. /* Alloca is builtin in gcc.  Use the builtin alloca if compiled with gcc. */
  105. #ifdef __GNUC__
  106. #define BUILTIN_ALLOCA
  107. #endif
  108.  
  109. /* Also, if this is a sun spark, use the builtin alloca. */
  110. #ifdef sun
  111. #ifdef sparc
  112. #define BUILTIN_ALLOCA
  113. #endif
  114. #endif
  115.  
  116. /* Define the proper alloca procedure. */
  117. #ifdef BUILTIN_ALLOCA
  118. #define alloca(x) __builtin_alloca(x)
  119. #else
  120. extern char *alloca();
  121. #endif
  122.  
  123. /* Malloc definition. */
  124. extern char *malloc();
  125.  
  126. /* String definitions. */
  127. #ifndef _HAVE_STRING
  128. #include <strings.h>
  129. #endif
  130.  
  131. /* The BSD defines are the default defines.  If something is not
  132.    defined above in the above conditional code, it will be set
  133.    in the following code to the BSD code.  */
  134.  
  135. /* Default block size.  Some systems do not have blocksize in their
  136.    stat record. This code uses the BSD blocksize from stat. */
  137.  
  138. #ifndef STATBLKSIZE
  139. #define STATBLKSIZE file_stat.st_blksize
  140. #endif
  141.  
  142.  
  143. /* Locking is done differently on different systems.  Here is the BSD
  144.    locking routines.  */
  145.  
  146. #ifndef UNLOCK_FILE
  147. #define UNLOCK_FILE(dbf) flock(dbf->desc, LOCK_UN)
  148. #define READLOCK_FILE(dbf) lock_val = flock(dbf->desc, LOCK_SH + LOCK_NB)
  149. #define WRITELOCK_FILE(dbf) lock_val = flock(dbf->desc, LOCK_EX + LOCK_NB)
  150. #endif
  151.  
  152. #ifndef TRUNCATE
  153. #define TRUNCATE(dbf) ftruncate (dbf->desc, 0)
  154. #endif
  155.  
  156. #ifndef OPEN
  157. #define OPEN(a,b,c) open(a,b,c)
  158. #endif